from syslogd.enums.Function import Function
from syslogd.enums.Priority import Priority
from syslogd.enums.Selector import Selector
import re


class RegexMatcher:

	function = '(' + Function.local1 + '|' + \
			   		 Function.local1 + '|' + \
			   		 Function.local2 + '|' + \
			         Function.local3 + '|' + \
			         Function.local4 + '|' + \
			         Function.local5 + '|' + \
			         Function.local6 + '|' + \
			         Function.local7 + '|' + \
		      	     Function.auth + '|' + \
			         Function.authpriv + '|' + \
			         Function.cron + '|' + \
			         Function.daemon + '|' + \
			         Function.kern + '|' + \
			         Function.lpr + '|' + \
			         Function.mail + '|' + \
			         Function.mark + '|' + \
		       	     Function.news + '|' + \
			         Function.syslog + '|' + \
			         Function.user + '|' + \
			         Function.uucp + ')'

	priority = '(' + Priority.debug + '|' + \
                     Priority.info + '|' + \
                     Priority.notice + '|' + \
                     Priority.warning + '|' + \
                     Priority.err + '|' + \
                     Priority.crit + '|' + \
                     Priority.alert + '|' + \
                     Priority.emerg + ')' 

	selector = '\\' + Function.all + '|(' + function + '[' + '\\' + Selector.comma + function + ']*)' + \
			   '\.(' + '\\' + Priority.all + '|' + Priority.none + '|([' + '\\' + Selector.equal + '|' + '\\' + Selector.diff + ']?' + priority + '))'

	selectors = selector + '(' + '\\' + Selector.semicolon + selector + ')*'
	regex = selectors

	def __init__(self):
		self.matcher = re.compile(RegexMatcher.regex)

	def match(self, string): 
		if self.matcher.search(string) == None:
			return False
		return True
